#pragma once

#include "Point3F.h"
#include "defines.h"

#include <stdlib.h>

// TEEM
#include <teem/nrrd.h>
#include <teem/biff.h>


class CVectorField
{
public:
	CVector3F *m_pVectorFields;
	float *m_pWeights;
	uint m_n;
	uint m_w;
	uint m_h;
	uint m_d;
	uint m_k;

public:
	CVectorField(void);
	~CVectorField(void);

public:
	int OpenVectorFieldFile(const char *pathname, FILE *fp = stdout);
	int SaveVectorFieldFile(const char *pathname, FILE *fp = stdout);

	void ClearVectorField();

	int CreateVectorField(const uint n, const uint w, const uint h, const uint d);
	int CreateVectorField(const uint w, const uint h, const uint d);

	uint GetWidth() { return m_w; }
	uint GetHeight() { return m_h; }
	uint GetDepth() { return m_d; }

	CVector3F GetVector(const uint x, const uint y, const uint z);
	CVector3F GetVector(const float x, const float y, const float z);
	void SetVector(const uint x, const uint y, const uint z, const CVector3F &v);
	void SetVector(const uint index, const CVector3F &v);

	CVector3F GetVectorFast(const uint x, const uint y, const uint z);
	CVector3F GetVectorFast(const uint index);

	bool IsZeroVector(const uint index);
	bool IsZeroVector(const uint x, const uint y, const uint z);

	int GetVectors(const CVector3F &pos, CVector3F *vecs);
	int GetVectors(const CVector3F *pos, CVector3F *vecs);
	int GetVectors(const uint x, const uint y, const uint z, CVector3F *vecs);

	void SetVector(const uint i, const uint j, CVector3F vec);
};

